package com.shujia.day15;

public class Code03ThreadOperation {

    public static void main(String[] args) {
        Runnable myRunnableThread = new MyRunnableThread();

        /*
            Thread类的构造方法：
                public Thread(Runnable target)
                    从Thread类中可以找到其构造方法为上述的内容，参数中要求传入一个 Runnable 的子实现类的对象

                public Thread(ThreadGroup group, String name)



            Runnable方式获取当前线程名称：
                方法1： Thread.currentThread().getName() -> 系统默认的名称
                方法2： 通过Thread构造方法传入自定义名称


         */
//        Thread thread1 = new Thread(myRunnableThread);
//        Thread thread2 = new Thread(myRunnableThread);

        Thread thread1 = new Thread(myRunnableThread,"张东东");
        Thread thread2 = new Thread(myRunnableThread,"柏杨");
        thread1.start();
        thread2.start();
    }

}


class MyRunnableThread implements Runnable {

    @Override
    public void run() {
        for (int i = 1; i <= 300; i++) {
            System.out.println(Thread.currentThread().getName() + "当前线程遍历到" + i);
        }
    }
}